package ru.urfc.portal.dao;

import javax.persistence.Query;

public class Paging {
	public static final Paging NULL_OBJECT = new Paging(null, null);
	public static final Paging ONE = new Paging(0, 1);
	
	private Integer startIndex;
	private Integer maxResults;
	
	public Paging(Integer startIndex, Integer maxResults) {
		super();
		this.startIndex = startIndex;
		this.maxResults = maxResults;
	}
	
	public Integer getStartIndex() {
		return startIndex;
	}
	
	public Integer getMaxResults() {
		return maxResults;
	}

	public void enchnceQuery(Query query) {
		if (startIndex != null) {
			query.setFirstResult(startIndex);
		}
		if (maxResults != null) {
			query.setMaxResults(maxResults);		
		}
	}

	public boolean isMaxResultsZeroOrNegative() {
		return maxResults!= null && maxResults <= 0;
	}
	
}
